package com.example.demo.controller;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.entity.WaresManageDetailType;
import com.example.demo.service.WaresManageDetailTypeService;
import com.example.demo.utils.JsonResult;
import com.example.demo.utils.ResultUtil;
import com.example.demo.utils.TimeUtil;
import com.example.demo.utils.UserInfoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * 货物明细类型管理
 */
@RestController
@RequestMapping(value = "/WaresManageDetailType")
public class WaresManageDetailTypeController {
    @Autowired
    private WaresManageDetailTypeService waresManageDetailTypeService;

    /**
     * 分页查询
     * @param
     * @return
     */
    @RequestMapping(value = "/getWaresManageDetailTypePage",method = RequestMethod.GET)
    public JsonResult getWaresManageDetailTypePage(@RequestParam(value = "current") Integer current,
                                                   @RequestParam(value = "size")Integer size){

        return ResultUtil.success("查询成功",waresManageDetailTypeService.page(new Page<>(current,size)));
    }

    /**
     * 添加
     * @param waresManageDetailType
     * @return
     */
    @RequestMapping(value = "/addWaresManageDetailType",method = RequestMethod.POST)
    public JsonResult addWaresManageDetailType(@RequestBody WaresManageDetailType waresManageDetailType){
        String userName = UserInfoUtil.gerUserName();
        String dateTime = TimeUtil.getDateTime();

        waresManageDetailType.setByName(userName);
        waresManageDetailType.setCreateDate(dateTime);
        waresManageDetailType.setDel(0);

        boolean save = waresManageDetailTypeService.save(waresManageDetailType);
        if(save){
            return ResultUtil.success("添加成功");
        }else{
            return ResultUtil.fail("添加失败");
        }
    }

    /**
     * 删除
     * @param
     * @return
     */
    @RequestMapping(value = "/delWaresManageDetailType/{id}",method = RequestMethod.DELETE)
    public JsonResult delWaresManageDetailType(@PathVariable Integer id){
        boolean b = waresManageDetailTypeService.removeById(id);
        if(b){
            return ResultUtil.success("删除成功");
        }else{
            return ResultUtil.fail("删除失败");
        }
    }

    /**
     * 修改
     * @return
     */
    @RequestMapping(value = "/editWaresManageDetailType",method = RequestMethod.PUT)
    public JsonResult editWaresManageDetailType(@RequestBody WaresManageDetailType waresManageDetailType){
        String userName = UserInfoUtil.gerUserName();
        String dateTime = TimeUtil.getDateTime();

        waresManageDetailType.setEditName(userName);
        waresManageDetailType.setUpdateDate(dateTime);

        boolean b = waresManageDetailTypeService.updateById(waresManageDetailType);
        if(b){
            return ResultUtil.success("修改成功");
        }else{
            return ResultUtil.fail("修改失败");
        }
    }


    /**
     *获取列表
     * @return
     */
    @RequestMapping(value = "/getWaresTypeManageList",method = RequestMethod.GET)
    public JsonResult getWaresManageDetailTypeList(){
        return  ResultUtil.success("查询成功",waresManageDetailTypeService.list(Wrappers.query(null)));
    }

}
